<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      #box {
        height: 400px;
        width: 400px;
        background-color: orange;
      }
    </style>
  </head>
  <body>
    <div id="box">
      <div
        id="d1"
        style="background-color: red; height: 200px; width: 200px"
      ></div>
    </div>
    <button onclick="changeStyle()">获取和修改属性</button> 
    <button onclick="htmlFun()">innerHTML</button>
    <button onclick="textFun()">innerTEXT</button>
   
    <script>
      var div_d1 = document.getElementById("d1");

      /*
       innerHTML:解析标签
       innerText:不会解析标签

        */
      function textFun(){
        div_d1.innerText="<h1>HelloHTML</h1>"
      }
      function htmlFun(){
        div_d1.innerHTML="<h1>HelloHTML</h1>"
      }

      function changeStyle() {
        
        console.log( div_d1.style.backgroundColor);
        console.log( div_d1.style.height);
        console.log( div_d1.style.width);

        div_d1.style.backgroundColor="skyblue";
        div_d1.style.width="300px";

      }
    </script>
  </body>
</html>
